// import React, { useState, useEffect } from "react";

// const App = () => {
//   const [count, setCount] = useState(1);

//   useEffect(() => {
//     setTimeout(() => {
//       console.log(count);
//     }, 1000);
//   }, [count]);

//   return (
//     <>
//       <h2>useRef</h2>
//       <p>count: {count}</p>
//       <button onClick={() => setCount((v) => v - 1)}>--</button>
//       <button onClick={() => setCount((v) => v + 1)}>++</button>
//     </>
//   );
// };

// export default App;

import React, { useRef } from "react";

const App = () => {
  const count = useRef(1);

  const fn = () => {
    count.current = count.current + 1;

    setTimeout(() => {
      console.log(count.current);
    }, 1000);
  };

  return (
    <>
      <h2>使用ref来绕过Capture Value 的特性</h2>
      <p>count: {count.current}</p>
      <button onClick={fn}>++</button>
    </>
  );
};

export default App;
